package com.caiwangdai.app.extension

import android.text.TextUtils
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*


//判断文本是否为空
fun String.isEmpty(): Boolean = TextUtils.isEmpty(this)


val DATE_FORMAT_TYPE_01 = "yyyy-MM-dd HH:mm:ss"
val DATE_FORMAT_TYPE_02 = "MM月dd日 HH:mm"

//String转Date
fun String.string2Date(format: String): Date = SimpleDateFormat(format, Locale.CHINA).parse(this)

//Date转String
fun Date.date2String(format: String): String = SimpleDateFormat(format, Locale.CHINA).format(this)


//显示倒计时[毫秒]
fun Long.showCountDownTime(): String {
    var seconds = this
    val day = seconds / (24 * 60 * 60)
    seconds %= (24 * 60 * 60)
    val hour = seconds / (60 * 60)
    seconds %= (60 * 60)
    val minute = seconds / 60
    val second = seconds % 60
    val sb = StringBuilder()
    if (day > 0)
        sb.append(day.toString() + "天")
    sb.append(hour.toString() + "小时")
    sb.append(minute.toString() + "分")
    sb.append(second.toString() + "秒")
    return sb.toString()
}